<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <!-- START 右侧数据 -->
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                    <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                        <div class="form-group">
                            <label class="control-label col-sm-1">Listing:</label>
                            <div class="col-sm-2">
                                <input type="text" name="relatedListingName" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">渠道:</label>
                            <div class="col-sm-2">
                                <select id="relatedChannelName" name="relatedChannelName"  class="form-control">
                                    <option value="">全部分类</option>
                                    <%for(var chan in channel){%>
                                    <option value="${chan.channelName}"  >${chan.channelName}</option>
                                    <%}%>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">ASIN:</label>
                            <div class="col-sm-2">
                                <input type="text"  name="relatedAsin" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">SKU:</label>
                            <div class="col-sm-2">
                                <input type="text"  name="relatedSku" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-1">FNSKU:</label>
                            <div class="col-sm-2">
                                <input type="text"  name="relatedFnSku" class="form-control">
                            </div>
                            <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                        </div>
                    </form>
                </div>
            </div>
            <!-- START 操作按钮 -->
            <form>
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <a class="add-btn btn btn-sm btn-success"><i class="fa fa-plus" aria-hidden="true"></i> 新增</a>
                <button  class="layui-btn layui-btn-normal layui-btn-sm" style="margin-top: -6px;margin-left: -4px" id="import-btn"  name="import-btn">
                    <i class="fa fa-plus" aria-hidden="true"></i> 导入SKU
                </button>
                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
                    <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                </button>
                <button  class="layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -2px">
                    <i class="fa fa-download"></i>
                    <a href="/excel/对照表SKU模板.xlsx" style="color: white" download>模板下载</a>
                </button>
                &nbsp;
                <button  class="layui-btn layui-btn-sm import-flag-btn layui-btn-warm" style="margin-top: -6px;margin-left: -4px" id="import-flag-btn"  name="import-flag-btn">
                    <i class="layui-icon"></i>
                    导入产品标信息
                </button>
            </div>
            </form>
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-side-pagination="server"
                   data-page-size="15"
                   data-url="/sea/operate/relatedSku/findByCnd.do"
                   class="table table-striped table-hover">
            </table>
            <!-- END 数据表格 -->

            <!-- END 右侧数据 -->
        </div>
    </div>
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload'}){}%>
<script>


    var $relatedTable = $('#relatedTable'),selections=[];
    $(function(){
        //新增
        $('.add-btn').on('click',function(){//新增
            layer.open({
                type: 2,
                area: ['100%','100%'],
                skin: 'layer-ext-espresso',
                content: ['/sea/operate/relatedSku/addSku.do', 'yes']
            });
        });
        //指定允许上传的文件类型
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: 'Listing',
                    field: 'relatedListingName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '渠道',
                    field: 'relatedChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'SKU',
                    field: 'relatedSku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '产品名称',
                    field: 'relatedProductName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '产品颜色',
                    field: 'productColorName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '产品属性',
                    field: 'productPropertyName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '尺码',
                    field: 'productSizeName',
                    align: 'center',
                    valign: 'middle'
                },

                {
                    title: 'FNSKU',
                    field: 'relatedFnSku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'ASIN',
                    field: 'relatedAsin',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '产品标',
                    field: 'relatedFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            var result='<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> <a href="'+v+'" download style="color: white">下载附件</a>';
                            result+='</button>';
                            return result;
                        }else{
                            return '';
                        }
                    }
                },
                {
                    title: '运营人员',
                    field: 'relatedOperateName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'operate',
                    title: '操作',
                    width:200,
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                $('.edit-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        content: ['/sea/operate/relatedSku/editSku.do?id='+id, 'yes']
                    });
                });

            }
        });
    });
    //操作菜单
    function optFormatter(value,row){
        var content = '<button class="edit-btn btn btn-xs btn-info" data-val="'+row.id+'" title="修改"><i class="fa fa-edit"></i>  </button>';
        return content;
    }


    $('.search-btn').on('click',function(){
           $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/operate/relatedSku/findByCnd.do?'+$('#search-form').serialize() });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/operate/relatedSku/export.do?'+$('#search-form').serialize();
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-btn', //绑定元素,
            accept:'file',
            url: '/sea/operate/relatedSku/import/', //上传接口
            data:{},
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $relatedTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-flag-btn', //绑定元素,
            accept:'file',
            url: '/sea/operate/relatedSku/importFlag/', //上传接口
            data:{},
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $relatedTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                            layer.closeAll();
                        }});

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });
</script>
</body>
</html>
